package com.teacold.customdemo.chapter_seven;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

import com.teacold.customdemo.R;

public class GrayShadowView  extends View {
    private Paint mPaint;
    private Path mPath;
    private Bitmap mBitmap,alphaBitmap;
    public GrayShadowView(Context context) {
        super(context);
        setLayerType(LAYER_TYPE_SOFTWARE,null);//禁止硬件加速
        mPaint=new Paint();
        mBitmap=BitmapFactory.decodeResource(getResources(), R.mipmap.menu_five);
        alphaBitmap=mBitmap.extractAlpha();
    }

    public GrayShadowView(Context context, AttributeSet attrs) {
        this(context);
    }

    public GrayShadowView(Context context, AttributeSet attrs, int defStyleAttr) {
        this(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int width=200;
        int height=width*alphaBitmap.getWidth()/alphaBitmap.getHeight();
        //绘制灰色阴影
        mPaint.setColor(Color.GRAY);
        mPaint.setMaskFilter(new BlurMaskFilter(10,BlurMaskFilter.Blur.OUTER));
        canvas.drawBitmap(alphaBitmap,null,new Rect(10,10,width,height),mPaint);
//        //绘制黑色阴影
//        canvas.translate(width,0);
//        mPaint.setColor(Color.BLACK);
//        canvas.drawBitmap(alphaBitmap,null,new Rect(10,10,width,height),mPaint);
        canvas.translate(-5,-5);
        mPaint.setMaskFilter(null);
        canvas.drawBitmap(mBitmap,null,new Rect(0,0,width,height),mPaint);
    }




}
